#include <stdio.h>

const int Type=3;

void init(int** dp,int n)
{
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<Type;j++)
        {
            dp[i][j]=-1;
        }
    }
}

/**
 *angle 第一个数 1递增 -1递减
 */
int dpFunc(int** input,int** dp,int n,int start,int angle){
    init(dp,n);

    int i,j,k;
    dp[0][start]=input[0][start];

    int tmpAngle=angle;
    int max;

    for(i=1;i<n;i++)
    {
        for(j=0;j<Type;j++)
        {
            k=j-tmpAngle;
            max=-1;
            while (k>=0&&k<Type)
            {
                if(dp[i-1][k]>max)
                {
                    max=dp[i-1][k];
                }
                k-=tmpAngle;
            }

            if(max>0)
            {
                dp[i][j]=max+input[i][j];
            }
            
        }
        //这个点上升下一个点就下降
        tmpAngle=-tmpAngle;
    }

    k=start+angle;
    max=-1;
    while (k>=0&&k<Type)
    {
        if(dp[n-1][k]>max)
        {
            max=dp[n-1][k];
        }
        k+=angle;
    }

    
    return max;
}

int main(){
    int n;
    int i;
    scanf("%d",&n);
    int** input=new int*[n];
    int** dp=new int*[n];
    for(i=0;i<n;i++)
    {
        input[i]=new int[Type];
        dp[i]=new int[Type];
        scanf("%d %d %d",&input[i][0],&input[i][1],&input[i][2]);
    }

    int start=0,angle=1;
    int max=dpFunc(input,dp,n,start,angle);

    start=1;
    int tmp=dpFunc(input,dp,n,start,angle);
    if(tmp>max)
    {
        max=tmp;
    }

    angle=-1;
    tmp=dpFunc(input,dp,n,start,angle);
    if(tmp>max)
    {
        max=tmp;
    }

    start=2;
    tmp=dpFunc(input,dp,n,start,angle);
    if(tmp>max)
    {
        max=tmp;
    }

    printf("%d\n",max);


    for(i=0;i<n;i++)
    {
        delete input[i];
        delete dp[i];
    }
    delete input;
    delete dp;
    return 0;
}